home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Text⁄Files / FaceLift / FaceLift Folder / FLMisc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-16  |  3.4 KB  |  191 lines  |  [TEXT/KAHL]

  1. # include    "TransSkel.h"
  2.  
  3. # include    "FLMaca.h"
  4. # include    "FaceLift.h"
  5.  
  6.  
  7. /* ---------------------------------------------------------------- */
  8. /*                            String Operations                        */
  9. /* ---------------------------------------------------------------- */
  10.  
  11. /*
  12.  * Copy src to dst
  13.  */
  14.  
  15. void
  16. CopyString (StringPtr src, StringPtr dst)
  17. {
  18.     BlockMove (src, dst, (long) (src[0] + 1));
  19. }
  20.  
  21.  
  22. /*
  23.  * Append src to dst
  24.  */
  25.  
  26. void
  27. AppendString (StringPtr src, StringPtr dst)
  28. {
  29.     BlockMove (&src[1], dst + dst[0] + 1, (long) src[0]);
  30.     dst[0] += src[0];
  31. }
  32.  
  33.  
  34. /*
  35.  * Compare two strings.
  36.  * Return:
  37.  *    0        s1 = s2
  38.  *    < 0        s1 < s2
  39.  *    > 0        s1 > s2
  40.  */
  41.  
  42. short
  43. CompareString (StringPtr s1, StringPtr s2)
  44. {
  45. int    i, len, diff;
  46.  
  47.     len = s1[0];
  48.     if (len > s2[0])
  49.         len = s2[0];
  50.     for (i = 1; i <= len; ++i)
  51.     {
  52.         if ((diff = s1[i] - s2[i]) != 0)
  53.             return (diff);
  54.     }
  55.     return (s1[0] - s2[0]);
  56. }
  57.  
  58.  
  59. /* ---------------------------------------------------------------- */
  60. /*                            Event Operations                        */
  61. /* ---------------------------------------------------------------- */
  62.  
  63.  
  64. /*
  65.  * Return true if there's a mouse-down event pending (also flush the
  66.  * event so that it's not used in some way other than as a signal.
  67.  */
  68.  
  69. Boolean
  70. MouseClick (void)
  71. {
  72. EventRecord    theEvent;
  73.  
  74.     if (EventAvail (mDownMask, &theEvent))
  75.     {
  76.         FlushEvents (mDownMask, 0);
  77.         return (true);
  78.     }
  79.     return (false);
  80. }
  81.  
  82.  
  83. /*
  84.  * Make a window the front window and update it before proceeding.
  85.  */
  86.  
  87. void
  88. MakeFrontWind (WindowPtr w)
  89. {
  90.     HiliteMenu (0);
  91.     SelectWindow (w);
  92.     ShowWindow (w);
  93.     SkelDoEvents (updateMask + activMask);
  94.     SetPort (w);
  95. }
  96.  
  97.  
  98. /* ---------------------------------------------------------------- */
  99. /*                            Memory Operations                        */
  100. /* ---------------------------------------------------------------- */
  101.  
  102.  
  103. Boolean
  104. ExpandHandle (Handle h, Size delta)
  105. {
  106. Size    newSize;
  107.  
  108.     newSize = GetHandleSize (h) + delta;
  109.     SetHandleSize (h, newSize);
  110.     return (GetHandleSize (h) == newSize);
  111. }
  112.  
  113.  
  114. /* ---------------------------------------------------------------- */
  115. /*                                Miscellaneous                        */
  116. /* ---------------------------------------------------------------- */
  117.  
  118.  
  119. Boolean
  120. DiscardChanges (void)
  121. {
  122. short    result;
  123.  
  124.     if (!mapModified)
  125.         return (true);
  126.     ParamText ("\pDiscard changes to current map?", "\p", "\p", "\p");
  127.     result = SkelAlert (questAlrtNum, SkelDlogFilter (nil, true),
  128.                                             skelPositionOnParentWindow);
  129.     SkelRmveDlogFilter ();
  130.     SkelDoUpdates ();
  131.     return (result == 2);    /* 2 is "OK" */
  132. }
  133.  
  134.  
  135.  
  136. Boolean
  137. DestroyWarn (void)
  138. {
  139. short    result;
  140.  
  141.     if (mapList->nLines == 0)    /* if nothing there, don't bother, */
  142.     {                            /* unless map has changed, then ask */
  143.         if (mapModified)        /* different question */
  144.             return (DiscardChanges ());
  145.         return (true);
  146.     }
  147.     ParamText ("\pThis operation destroys the current map.",
  148.                 "\p Do you wish to proceed?", "\p", "\p");
  149.     result = SkelAlert (questAlrtNum, SkelDlogFilter (nil, true),
  150.                                             skelPositionOnParentWindow);
  151.     SkelRmveDlogFilter ();
  152.     SkelDoUpdates ();
  153.     return (result == 2);    /* 2 is "OK" */
  154. }
  155.  
  156.  
  157. /*
  158.  * Display a message in a generic alert.
  159.  */
  160.  
  161. void
  162. Message (StringPtr s1, StringPtr s2, StringPtr s3, StringPtr s4)
  163. {
  164.     ParamText (s1, s2, s3, s4);
  165.     (void) SkelAlert (msgeAlrtNum, SkelDlogFilter (nil, true),
  166.                                             skelPositionOnParentDevice);
  167.     SkelRmveDlogFilter ();
  168.     SkelDoUpdates ();
  169. }
  170.  
  171.  
  172. void
  173. Message1 (StringPtr s1)
  174. {
  175.     Message (s1, "\p", "\p", "\p");
  176. }
  177.  
  178.  
  179. void
  180. Message2 (StringPtr s1, StringPtr s2)
  181. {
  182.     Message (s1, s2, "\p", "\p");
  183. }
  184.  
  185.  
  186. void
  187. Message3 (StringPtr s1, StringPtr s2, StringPtr s3)
  188. {
  189.     Message (s1, s2, s3, "\p");
  190. }
  191.